package com.dbManage.page.Tag;

import com.dbManage.dao.CustomTagDao;
import com.dbManage.entity.CustomTag;
import com.dbManage.entity.User;
import com.dbManage.exception.CommonException;
import com.dbManage.tools.SessionTool;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;

@Repository
public class CustomTagService {

    @Resource
    CustomTagDao customTagDao;

    public void addCustomTag(CustomTag tag) throws CommonException {
        CustomTag ct = customTagDao.findCustomTagByTagName(tag.getTag().replaceAll("\\s+","").trim());
        if(ct!=null) throw new CommonException("标签已存在!");
        User user= SessionTool.getUser();
        tag.setUid(user.getId());
        tag.setTag(tag.getTag().toLowerCase());
        customTagDao.insertTag(tag);
    }
}
